package sites.manager.admin.role;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
import sites.manager.common.kit.Ret;
import sites.manager.common.kit.SiteInfo;

/**
 * 角色校验器
 */
public class RoleValidator extends Validator {
    @Override
    protected void validate(Controller controller) {
        setShortCircuit(true);
        validateRequired("name", SiteInfo.msgKey, "名称不可为空！");
        validateString("name", 1, 60, SiteInfo.msgKey, "昵称最长为50个字符！");
    }

    @Override
    protected void handleError(Controller controller) {
        Ret ret = Ret.fail(SiteInfo.msgKey, controller.getAttr(SiteInfo.msgKey));
        controller.renderJson(ret);
    }
}
